﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls.Primitives;

namespace MuddyBoots.GreenlightQC.Mobile.UI.Helpers
{
    public static class ControlTreeHelper
    {
        public static IEnumerable<T> FindLogicalChildren<T>(this DependencyObject obj) where T : DependencyObject
        {
            if (obj != null)
            {
                if (obj is T)
                {
                    yield return obj as T;
                }

                foreach (DependencyObject child in LogicalTreeHelper.GetChildren(obj).OfType<DependencyObject>())
                {
                    foreach (T c in FindLogicalChildren<T>(child))
                    {
                        yield return c;
                    }
                }
            }
        }
    }
}
